/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ejb;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author Cuchu
 */
@Stateless
public class RecensioneInternaFacade extends AbstractFacade<RecensioneInterna> implements RecensioneInternaFacadeLocal {

    @PersistenceContext(unitName = "webApplication-ejbPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public RecensioneInternaFacade() {
        super(RecensioneInterna.class);
    }
 
    @Override
    public boolean esistente(RecensioneInterna r) {
         return ! (em.createQuery("select autore,dataPubblicazione,videogiochi "
                 + "from RecensioneInterna where autore='"+r.getAutore()+
                 "' AND dataPubblicazione="+r.getData()).getResultList().isEmpty());
    }

    @Override
    public RecensioneInterna getRecensioneInterna(Long id) {
            return (RecensioneInterna)(em.createQuery("select * from RecensioneInterna where UPPER(id) ='" + id + "'").getSingleResult());  
    }
}
